//Obtiene la vista del formulario de registro

function getHtml_admin( option ){
	img = "<img src='../includes/images/ajax.gif' />";
	//$("#message").show(1000);
	$("#message").html(img);
	
	url = "";
	workzone = "";
	switch(option){
		case 0:
			url="problems.php";
		break;
		case 1:
			url="new_problem.php";
			workzone="2";
		break;
		case 2:
			url="mod_user.php";
			workzone="2";
		break;
		case 3:
			url="mod_problem.php";
			workzone="2";
		break;
	}
   $.ajax({
   type: "POST",
   url: url,
   //data: "name=John&location=Boston",
   success: function(data){
     $("#workzone"+workzone).html(data);
	$("#message").html("");	 
	// $("#message").hide(1000);
   }
   
 });
}


function newProblem(){
	img = "<img src='../includes/images/ajax.gif' />";	
	$("#message").html(img);
	tit =  trim($("#protit").val());
	cat =  $("#procat").find('option:selected').val();
	niv = $("#proniv").find('option:selected').val();
	tmp = trim($("#protiem").val());
	fuent = trim($("#profuent").val());
	prob = trim($("#propro").val());
	sol = trim($("#prodesc").val());
	casoin = trim($("#procasein").val());
	casoout = trim($("#procaseout").val());
	
	color = "#F7D1D1";	
	color2 = "#EEEEEE";
	
	//checar campos vacios
	if( tit == "" || cat == "" || niv == "" || tmp == "" || fuent == ""  || prob == "" || sol == "" || casoin == "" || casoout == ""){
		if(tit == "" ) $("#tit").css("backgroundColor",color); else $("#tit").css("backgroundColor", color2);
		if(cat == "" )$("#cat").css("backgroundColor",color);	else $("#cat").css("backgroundColor", color2);
		if(niv == "" ) $("#niv").css("backgroundColor",color); else $("#niv").css("backgroundColor", color2);
		if(tmp == "" )$("#tmp").css("backgroundColor",color);	else $("#tmp").css("backgroundColor", color2);
		if(fuent == "" ) $("#fuent").css("backgroundColor",color); else $("#fuent").css("backgroundColor", color2);
		if(prob == "" )$("#prob").css("backgroundColor",color);	else $("#prob").css("backgroundColor", color2);
		if(sol == "" ) $("#sol").css("backgroundColor",color); else $("#sol").css("backgroundColor", color2);
		if(casoin == "" )$("#casoin").css("backgroundColor",color);	else $("#casoin").css("backgroundColor", color2);
		if(casoout == "" )$("#casoout").css("backgroundColor",color);	else $("#casoout").css("backgroundColor", color2);
		$("#message").html("Debes llenar todos los campos.");
		return;
	}
	//enviar los valores al .php CAMBIAR ESTA FUNCION POR UN CAPAZ DE HACER UN ENVIO PORMEDIO DEL METODO POST
	$.getJSON('../controllers/problems.php?',{action:1,tit:tit,cat:cat,niv:niv,tmp:tmp,fuent:fuent,prob:prob,sol:sol,casoin:casoin,casoout:casoout},function(data) {		
		if(data.status == "error"){			
			
			$("#message").html(data.error);
			//setTimeout('$("#message").hide(1000)',3000);
		}
		else {
			$("#message").html("Problema registrado.");
			getHtml_admin(1);
		}		
	});
}
